package com.wjm.demo.test1.net_test.tcp_socket_test.uploadtext;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class UploadServer {
    public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(10001);
        Socket accept = ss.accept();
        System.out.println(accept.getInetAddress().getHostAddress() + ".......connected");
        BufferedReader br = new BufferedReader(new InputStreamReader(accept.getInputStream()));
        BufferedWriter bw = new BufferedWriter(new FileWriter("d:\\server.txt"));
        String line = null;
        while ((line = br.readLine()) != null) {
            if ("over".equals(line)) {
                break;
            }
            bw.write(line);
            bw.newLine();
            bw.flush();
        }
        PrintWriter pw = new PrintWriter(accept.getOutputStream(), true);
        pw.println("上传成功");

        bw.close();

        accept.close();
        ss.close();
    }
}
